      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ul class="nav nav-tabs mytabs" id="tabs">
  		  	 <li  class="active" data-aim="searchbox"><a href="#">用户列表</a></li>
           <li data-aim="importbox"><a href="#">导入数据</a></li>
           <li data-aim="deletebox"><a href="#">批量删除</a></li>
  		  </ul>
        <div style="padding-bottom:20px;" class="sh" id="searchbox">

          <label for="lastName" class="control-label">学校</label>
          <select name="" class="school input" >

          </select>
          <label for="firstName" class="control-label">年级</label>
          <select name="" class="grade input" >

          </select>
          <label for="lastName" class="control-label">班级</label>
          <select name="classes" class="class input" id="cla">

          </select>
          <label for="">姓名</label>
          <input id="name" type="input" class="input" size="10">
          <label  for="">学号</label>
          <input id="sno" type="input" class="input">
          <button id="search" class="btn btn-primary">搜索</button>
          <a  class="btn btn-primary" href="<?=site_url('/user/add')?>">添加新用户</a>

          <a id="exportExcel" href="<?=site_url('/user/exportNoCard')?>" class="btn btn-primary">导出无卡名单</a>
          <a id="exportAllUser" href="<?=site_url('/user/exportAllUser')?>" class="btn btn-primary">导出所有用户</a>

        </div>
        <div class="sh" style="padding-bottom:10px;display:none;" id="importbox">
          <div class="import1">
            <div class="bg-danger" style="padding:10px 20px ;margin-bottom:15px;">请确保excel仔细校对无误后再上传，
              <a href="<?=base_url('/download/template.xlsx')?>"><i class="icon iconfont icon-down"></i>导入模版下载</a>
            </div>
             <label for="lastName" class="control-label">学校</label>
            <select name="" class="school" >

            </select>
            <label for="firstName" class="control-label">年级</label>
            <select name="" class="grade" >

            </select>
            <label for="lastName" class="control-label">班级</label>
            <select name="classes" class="class" id="cla2">

            </select>
            <input type="hidden" name="filePath" >
            <input type="file" id="excel" name="Filedata" style="display:inline;">
            <button id="importData">导入</button>
          </div>

          <!--
          <div class="import2" style="padding-top:10px;">
            <label for="lastName" class="control-label">学校</label>
           <select name="" class="school" id="schools" >

           </select>

           <input type="hidden" name="filePath2" >
           <input type="file" id="excel2" name="Filedata" style="display:inline;">
           <button id="importDatas">导入</button>
         </div>-->

        </div>

        <div class="sh" style="padding-bottom:10px;display:none;" id="deletebox">
           <label for="lastName" class="control-label">学校</label>
          <select name="" class="school" >

          </select>
          <label for="firstName" class="control-label">年级</label>
          <select name="" class="grade" >

          </select>
          <label for="lastName" class="control-label">班级</label>
          <select name="classes" class="class" id="cla3">

          </select>

          <button id="deleteData">批量删除</button>

        </div>
          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>家长姓名</th>
                      <th>手机号</th>
                      <th class="table-sort" data-name="order" data-up="0" data-down="1" data-current="0">学生姓名</th>
                      <th>班级</th>
                      <th>卡号</th>
                      <th>学号</th>
                      <th>余额操作</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($users as $item):?>
                    <tr>
                      <td><?php echo $item['id'];?></td>
                      <td><?php echo $item['pname'];?></td>
                      <td><?php echo $item['phone'];?></td>
                      <td><?php echo $item['sname'];?></td>
                      <td><?php echo $item['gname'].$item['cname'];?></td>
                      <td><?php echo $item['no'];?></td>

                      <td><?php echo $item['sno'];?></td>
                       <td>
                          <a href="javascript:void(0)" class="reset-password" data-id="<?=$item['id']?>" data-name="<?=$item['sname']?>">重置密码</a> |
                          <a href="<?php echo site_url('user/edit/id/'.$item['id'])?>" >编辑</a> |
                      	   <a href="<?php echo site_url('user/recharge/id/'.$item['id'])?>" >充值</a>
                      	    | <a href="#" class="del" data-id="<?php echo $item['id'];?>" >删除</a>
                       </td>
                     </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div>
              <div class="pagination" style="margin-bottom:20px;">
              <?php  echo $links; ?>
            </div>
            </div>
          </div>
        </div>
      </div>

<script type="text/javascript" src="<?=base_url('js/table-sort.js')?>">

</script>
<script>
	$(document).ready(function() {

    // 充值密码
    $('.reset-password').click(function(){
      var id = $(this).data('id')
      var name= $(this).data('name')
      if(confirm('确定重置 '+name+' 的密码？')){
        $.ajax({
          url: '<?=site_url("/user/resetPassword")?>',
          type: 'post',
          data: {
            userid: id
          },
          success: function(d){
            alert(d.msg)
          },
          error: function(){

          },
          dataType: 'json'
        })
      }
    })

    $('#excel').ajaxfileupload({
        'action' : '<?php echo site_url('up/up_pic')?>',
        'params' : {
          'path' : 'product/pic'
        },
        onStart: function() {

        },
        'onComplete' : function(response) {
          if ( typeof response === 'string') {
            var files = response.replace(/\\/g, '/');
            //$("#img_product").attr("src",'http://7xj0kd.com2.z0.glb.qiniucdn.com/'+files);
            $("input[name='filePath']").val(files);

          } else {
            alert("上传的文件格式不正确");
          }
        }
      });

      $('#excel2').ajaxfileupload({
          'action' : '<?php echo site_url('up/up_pic')?>',
          'params' : {
            'path' : 'product/pic'
          },
          onStart: function() {

          },
          'onComplete' : function(response) {
            if ( typeof response === 'string') {
              var files = response.replace(/\\/g, '/');
              //$("#img_product").attr("src",'http://7xj0kd.com2.z0.glb.qiniucdn.com/'+files);
              $("input[name='filePath2']").val(files);

            } else {
              alert("上传的文件格式不正确");
            }
          }
        });


      //导入班级数据
    $('body').on('click', '#importData', function(){
      var file = $('input[name="filePath"]').val()
      var classId = $('#cla2').val()

      if(file == '' || classId == '' || file == undefined || classId == undefined
        || classId == null || classId == 0) {
        alert('班级或者文件不能为空')
      }
      $.ajax({
        url: '<?=site_url("/user/importUser")?>',
        type: 'post',
        data: {
          file: file,
          'class': classId
        },
        success: function(d){
          alert(d.msg)
          if(d.code){
            window.location.reload();
          }
        },
        error: function(){

        },
        dataType: 'json'
      })
    })

    //导入学校数据
    $('body').on('click', '#importDatas', function(){
      var file = $('input[name="filePath2"]').val()
      var school = $('#schools').val()



      if(file == '' || school == '' || file == undefined || school == undefined) {
        alert('学校或者文件不能为空')
      }
      $.ajax({
        url: '<?=site_url("/user/importUsers")?>',
        type: 'post',
        data: {
          file: file,
          'school': school
        },
        success: function(d){
          alert(d.msg)
          if(d.code){
            window.location.reload();
          }
        },
        error: function(){

        },
        dataType: 'json'
      })
    })


		$(".del").click(function() {
			if(confirm("确定要删除该学生吗？"))
			{
				var id = $(this).attr("data-id");
				$.ajax({
					url : '<?php echo site_url('user/delete')?>',
					type : "post",
					async : false,
					data : {
						'id' : id
					},
					dataType : "json",
					success : function(data) {
						if(data.code)
						{
							alert(data.msg);
							window.location.reload();
						}else{
							alert(data.msg);
						}
					}
				});
			}
		});
	});
</script>
<script>
var schoolid = 0;
  $(document).ready(function() {
     $.ajax({
       url: "<?=site_url('/user/getschools')?>",
       type: 'post',
       data: {},
       success: function(d){
         if(d.code){
          $('.school').html(initOptionSchool(d.data));
          //initOption(d);
          //$("#school").trigger("change");
         }
       },
       error: function(){

       },
       dataType: 'json'
     })

     $('.school').change(function(){
      var type = $(this).val();
      schoolid = type.split('-')[0];
      var _this = $(this);
      $.ajax({
        url: "<?=site_url('/user/getgrades')?>",
        type: 'post',
        data: {
          type: type.split('-')[1]
        },
        success: function(d){
          if(d.code){
            _this.parents('.sh').find('.grade').html(initOption(d.data));
            _this.parents('.sh').find('.class').html('')

            //$('#grade').trigger('change')
          } else {
            console.log(d.msg)
          }
        },
        error: function(){

        },
        dataType: 'json'
      })
     })

     $('.grade').change(function(){
      var sid = $(this).val();
      var _this = $(this);
      $.ajax({
        url: "<?=site_url('/user/getclasses')?>",
        type: 'post',
        data: {
          school: schoolid,
          grade: sid
        },
        success: function(d){
          if(d.code){

             _this.parents('.sh').find('.class').html(initOption(d.data));
          } else {
            console.log(d.msg)
          }
        },
        error: function(){

        },
        dataType: 'json'
      })
     })


     function initOption(data){
      var tmp = '<option value="0">请选择</option>';;
      for(var i= 0; i<data.length; i++){
        tmp += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
      }
      return tmp;
     }

     function initOptionSchool(data){
      var tmp = '<option value="0">请选择学校</option>';
      for(var i= 0; i<data.length; i++){
        tmp += '<option value="' + data[i].id + '-' + data[i].type + '">' + data[i].name + '</option>';
      }
      return tmp;
     }


  });


  $('body').on('click', '#search', function(){
    var classId = $('#cla').val()||0;
    var sno = $('#sno').val()||0;
    var name  = $('#name').val();
    window.location.href = '<?=site_url('/user/index')?>' + '/class/' + classId + '/sno/' + sno + '/name/' + name
  })

  //批量删除
  $('body').on('click', '#deleteData', function(){
    var classId = $('#cla3').val();
    var reg = /^\d+$/;


    if(reg.test(classId) && classId != 0){
      if(!confirm('确定要删除该班级？删除后数据无法恢复')){
        return;
      }
      $.ajax({
        url: '<?=site_url('user/deleteUsers')?>',
        type: 'post',
        data: {
          'class': classId
        },
        success: function(d){
          alert(d.msg)
          if(d.code){
            window.location.reload();
          }
        },
        error: function(){

        },
        dataType: 'json'
      })
    } else {
      alert('请选择要删除的班级')
    }
  })

  //tab切换
  $('#tabs li').click(function(){
    $('#tabs li').each(function(){
      $(this).removeClass('active');
    })
    $(this).addClass('active');
    var aim = $(this).data('aim');
    $('.sh').css('display', 'none');
    $('#' + aim).css('display', 'block')
  })
</script>
